package com.woniuxy.rms.controller;

import com.github.pagehelper.PageInfo;
import com.woniuxy.rms.advice.LogPoint;
import com.woniuxy.rms.pojo.Property;
import com.woniuxy.rms.service.PropertyService;
import com.woniuxy.rms.util.DataResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.servlet.ModelAndView;

import java.util.List;

/**
 * Auther: ChenGang  <br/>
 * Date: 2020/3/30 0030:下午 4:03  <br/>
 * Description:物业控制层
 */
@Controller
@RequestMapping("/pro")
public class PropertyController {

    @Autowired
    PropertyService propertyService;
    /**
     * Description : 物业列表,支持模糊查询  <br/>
     * ChangeLog : 1. 创建 (2020/3/31 0031 下午 9:09 [Administrator]);
     * @param currentPage 当前页
     * @param pageSize 页码
     * @param company 公司
     * @param companyPlace 公司地址
     * @param status 审核状态
     * @return com.woniuxy.rms.util.DataResult
    */
    @GetMapping("/list")
    @ResponseBody
    @LogPoint("查看物业")
    public DataResult list(@RequestParam(defaultValue = "1",required = false,name = "page") Integer currentPage,
                           @RequestParam(defaultValue = "10",required = false,name = "limit") Integer pageSize,
                           @RequestParam(required = false) String company,
                           @RequestParam(required = false) String companyPlace,
                           @RequestParam(required = false) Integer status){
        List<Property> properties = propertyService.findByPage(currentPage, pageSize,company,companyPlace,status);
        PageInfo info = new PageInfo(properties);
        return DataResult.success(info);
    }
    /**
     * Description : 物业审核  <br/>
     * ChangeLog : 1. 创建 (2020/3/30 0030 下午 4:15 [Administrator]);
     * @param property
     * @return com.woniuxy.rms.util.DataResult
    */
    @PutMapping("/checkPro")
    @ResponseBody
    @LogPoint("物业审核")
    public DataResult checkPro(Property property){
        return propertyService.checkPro(property);
    }
    /**
     * Description : 删除物业人员  <br/>
     * ChangeLog : 1. 创建 (2020/3/30 0030 下午 4:30 [Administrator]);
     * @param id
     * @return com.woniuxy.rms.util.DataResult
    */
    @DeleteMapping("/delete")
    @ResponseBody
    @LogPoint("删除物业人员")
    public DataResult delete(Long id){
        return propertyService.deleteById(id);
    }
    /**
     * Description : 跳转到小区列表  <br/>
     * ChangeLog : 1. 创建 (2020/3/30 0030 下午 4:56 [Administrator]);
     * @param proId
     * @param modelAndView
     * @return org.springframework.web.servlet.ModelAndView
    */
    @GetMapping("/proPlot")
    public ModelAndView proPlot(Long proId, ModelAndView modelAndView){
        modelAndView.setViewName("/property/propertyPlo");
        modelAndView.addObject("proId",proId);
        return modelAndView;
    }
    /**
     * Description : 退出小区  <br/>
     * ChangeLog : 1. 创建 (2020/4/8 0008 下午 5:14 [Administrator]);
     * @param id
     * @return com.woniuxy.rms.util.DataResult
    */
    @PutMapping("/exitPlot")
    @ResponseBody
    public DataResult exitPlot(Integer id){
        return propertyService.exitPlot(id);
    }
}